package servlet;
import servlet.Connections;
import java.sql.*;
import java.io.*;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class DeveloperProjectFormSubmit
 */
public class DeveloperProjectFormSubmit extends HttpServlet {
	private static final long serialVersionUID = 1L;
	
	Connections conn=new Connections();
	PreparedStatement pstmt=null;
	Statement stmt=null;
	ResultSet rs=null;
	String query,devidquery,developerName,loc,pname;
	int value,updateQuery=0;
    PrintWriter out;   
    
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException 
	{
		try
		{
			out=response.getWriter();	
			developerName=request.getParameter("selDeveloper");
			out.println(developerName);
			loc=request.getParameter("locationtext");
			out.println(loc);
			pname=request.getParameter("projecttext");
			out.println(pname);
			devidquery="select developer_Id from developer where developer_Name	='"+developerName+"'";
			out.println(devidquery);
			stmt=conn.getConnection().createStatement();
			rs=stmt.executeQuery(devidquery);
			while(rs.next())
			{
				value=rs.getInt(1);
			}
			
			out.println(""+value);
			
			query="insert into developerproject(Developer_id,Project_Name,Project_Location)values(?,?,?)";
			out.println(query);
			pstmt=conn.getConnection().prepareStatement(query);
			pstmt.setInt(1,value);
			pstmt.setString(2,pname);
			pstmt.setString(3,loc);
			updateQuery=pstmt.executeUpdate();
			
			if(updateQuery!=0)
				response.sendRedirect("DeveloperProjects.jsp");
			else
				out.println("Data not saved");
			
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
	}

}
